package loengud.kaheksa;

import java.awt.Graphics;
import java.awt.Point;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JFrame;

public class PaintiDemomine extends JFrame implements MouseMotionListener {

	List<Point> pts = new ArrayList<Point>();
	
	public static void main(String[] args) {
		PaintiDemomine d = new PaintiDemomine();
		d.setVisible(true);
		d.addMouseMotionListener(d);
	}

	
	@Override
	public void update(Graphics g) {
		paint(g);
	}
	@Override
	public void paint(Graphics g) {
		Point last = null;
		for (Point p : pts) {
			
			if (last == null) {
				last = p;
				continue;
			}
			
			g.drawLine(last.x, last.y, p.x, p.y);
			last = p;
		}
	}
	
	@Override
	public void mouseDragged(MouseEvent e) {
		pts.add(e.getPoint());
		repaint();
	}

	@Override
	public void mouseMoved(MouseEvent e) {}
}
